package com.os.opencv.java.chapter11;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.Scalar;
import org.opencv.features2d.FastFeatureDetector;
import org.opencv.features2d.Features2d;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class Fast {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        //读取图像并在屏幕上显示
        Mat src = Imgcodecs.imread("pics/goChild.png", Imgproc.COLOR_BGR2GRAY);
        Mat dst = new Mat();
        Imgproc.cvtColor(src, dst, Imgproc.COLOR_BGR2GRAY);
        HighGui.imshow("gray", dst);
        HighGui.waitKey(0);

        //用fast算法进行角点检测
        FastFeatureDetector fast = FastFeatureDetector.create(FastFeatureDetector.THRESHOLD);
        MatOfKeyPoint pts = new MatOfKeyPoint();
        fast.detect(src, pts);

        //在scr上画出角点
        Scalar red = new Scalar(0,0,255);
        int flag = Features2d.DrawMatchesFlags_DRAW_RICH_KEYPOINTS;

        Features2d.drawKeypoints(src, pts, src, red, flag);
        //在屏幕上显示检测结果
        HighGui.imshow("fast", src);
        HighGui.waitKey(0);

        System.exit(0);
    }
}
